package gdufs.stat.service;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

public class Utils {

	/**
	 * 从webseal获取当前用户Id，测试环境中，配置名为testUserId的jvm参数
	 * @param request
	 * @return
	 */
	public static String getCurrentUserId(HttpServletRequest request){
		String userId = request.getRemoteUser();
		String ivUser = request.getHeader("iv-user");
		if("Unauthenticated".equalsIgnoreCase(ivUser)){
			ivUser = null;
		}
		if (ivUser != null && ivUser.startsWith("uid=")) {
			userId = ivUser.split(",")[0].split("=")[1];
		}
		if(StringUtils.isEmpty(userId)){
			userId = System.getProperty("testUserId");
		}
		
		return userId;
	}
	
}
